<?php
namespace Admin\Controller;
use Think\Controller;
class KnowController extends AdminController {
	//苗木知识
    public function index(){
    	$this->know=M('know')->select();
    	$this->count=M('know')->count();
    	$this->sort=M('musort')->select();
    	$this->display();
    }
    //添加苗木知识页面
    public function add_know_page(){
    	$this->s=M('musort')->select();
    	$this->display();
    }
    //添加苗木知识
    public function add_know(){
        $data['sort'] = I('parentid');
    	$data['title']=I('title');
    	$data['content']=I('content');
    	$data['time']=time();
    	if(M('know')->add($data)){
    		echo 1;
    	}else{
    		echo 2;
    	}
    }
    //添加苗木类别页面
    public function add_sort_page(){
    	$this->display();
    }
    //添加苗木类别
    public function add_sort(){
    	$data['sort']=I('sort');
        if(M('musort')->add($data)){
            echo 1;
        }else{
            echo 2;
        }
    }
    //修改苗木知识页面
    public function save_know_page(){
    	$id = I('id');
    	$know=M('know')->where("id='$id'")->find();
    	$this->sort=M('musort')->select();
    	$this->assign('know',$know);
    	$this->assign('id',$id);
    	$this->display();
    }
    //修改苗木知识
    public function save_know(){
    	$id = I('id');
        $data['sort'] = I('parentid');
    	$data['title']=I('title');
    	$data['content']=I('content');
    	$data['time']=time();
    	if(M('know')->where("id='$id'")->save($data)){
    		echo 1;
    	}else{
    		echo 2;
    	}
    }
    //删除
    public function del(){
    	$id = I('id');
    	if(M('know')->where("id='$id'")->delete()){
    		echo 1;
    	}else{
    		echo 2;
    	}
    }
}